package com.liu.messageQueue.controller;

import com.liu.common.commons.Constants;
import com.liu.messageQueue.service.RabbitMQSendService;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/**
 * @author liuxinghong
 * @Description: 项目启动后  执行该方法
 * @date 2019/6/20 002011:46
 */
@Component
@Slf4j
public class RabbitMQTestComponent  {

    @Value("${rabbitmq.delayed-queue-name}")
    private String delayedQueueName;

    @Value("${rabbitmq.delayed-exchange-name}")
    private String delayedExchange;

    @Value("${rabbitmq.msg-send-queue}")
    private String msgSendQueueName;

    @Value("${rabbitmq.msg-send-exchange}")
    private String msgSendExchangeName;

    @Autowired
    private RabbitMQSendService rabbitMQSendService;

    @Scheduled(cron = "1 * * * * ?")
    public void onApplicationEvent() {
        System.out.println("发送测试消息");
        log.info("发送测试消息");
        for (int i= 1; i<100; i++){
            rabbitMQSendService.sendMessage(msgSendExchangeName,msgSendQueueName,"普通消息发送"+ DateTime.now().toString(Constants.YYYY_MM_DD_HH_MM_SS));
            rabbitMQSendService.sendDelayedMessage(delayedExchange,delayedQueueName,30000,"延时消息发送"+ DateTime.now().toString(Constants.YYYY_MM_DD_HH_MM_SS));
        }
    }
}
